<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/smoothness/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js"></script>
<script>

    function DeleteQuestion(pqd)
    {
        var data = {};
        var t = JSON.stringify({params: {method:'delete', position_question_id: pqd} });
        data.params = t;
        var ret = '';

        $.ajax({
            type: "POST",
            url: 'http://140.211.68.130/UpdateQuestionnaire',
            data: data,
            async: false,
            success: function(data){
                ret = data;
            },
            dataType: "json"
        });
        location.reload();
    }
</script>
<%
   def generate_url(url, params = {})
     uri = URI(url)
     uri.query = params.to_query
     uri.to_s
   end
%>
<head>
  <style>
      table, th, td {
          border: 1px solid black;
          border-collapse: collapse;
      }
      th,td {
          padding: 15px;
          text-align: center;
      }
  </style>
</head>
<body>
<div width="90%">
  <iframe id="the_editor" src="http://140.211.68.130/view/questioneditor.html?position_type_id=#{@position_type_id}" name="the_editor" align="right" height="900" width="20%" align="right"></iframe>
  <%= link_to 'Back to Positions', {:controller => 'staffing_expert', :action => 'home'} %>
  <h1 align="center">View/Edit Questions</h1>

  <table style="width:70%"; bgcolor="#F6F6FF">

    <tr>
      <th> Question ID</th>
      <th> Question Type</th>
      <th> Question Text </th>
      <th> Position ID</th>
      <th> Questionnaire Type </th>
      <th> Edit </th>
      <th> Remove </th>
    </tr>


    <% @full.each do |question| %>
        <tr>

          <% question.each do |field| %>
              <td>
                <% if(field[0] == 'type' && field[1] == 'multiple_choice') %>
                    Multiple Choice
                <% elsif(field[0] == 'type' && field[1] == 'text_box') %>
                    Short Answer
                <% elsif(field[0] == 'application_state' && field[1] == '1') %>
                    Kiosk
                <% elsif(field[0] == 'application_state' && field[1] == '2') %>
                    Phone
                <% else %>
                    <%= field[1] %>
                <% end %>
              </td>
          <% end %>

          <td><%= link_to '<button>Edit</button>'.html_safe,  "http://140.211.68.130/view/questioneditor.html?position_question_id=#{question['position_question_id']}", {:method => 'get', :target => 'the_editor'} %></td>
          <td><button onclick='DeleteQuestion(<%= question['position_question_id'] %>);'>Remove</button></td>

        </tr>
    <% end %>

  </table>
  <br> </br>
  <%= link_to '<button>Add Question</button>'.html_safe,  "http://140.211.68.130/view/questioneditor.html?position_type_id=#{@position_type_id}", {:method => 'get', :target => 'the_editor'} %>

</div>
</body>
